<?php
include("http://02d2e0a.netsolhost.com/includes/head.inc");
// include database functions/connections
include("./db.php");
// connect to the database
dbConnect('kar_web1');
?>
<script language="JavaScript">
//Validation to verify all fields are filled out...
function checkForm()
{
   var fname, lname, uname, pnumber, haddress, ephone, email;
   with(window.document.register)
   {
      fname = FirstName;
	  lname = LastName;
	  uname = userName;
	  pnumber = PhoneNumber;
	  haddress = HomeAddress;
	  ephone = EmergencyPhone;
	  email = EMail;
   }
   //CHECKS ALL FIELDS FOR BLANKS
   if (trim(fname.value) == "")
   {
      alert('Please enter your First Name');
	  fname.focus();
   }
   else if(trim(lname.value) == "")
   {
      alert('Please enter your Last Name');
	  lname.focus();
   }
   else if(trim(uname.value) == "")
   {
      alert('Please enter a User Name');
	  uname.focus();
   }
   else if(trim(pnumber.value) == "")
   {
      alert('Please enter a Phone Number');
	  pnumber.focus();
   }
   else if(trim(haddress.value) == "")
   {
      alert('Please enter your Address');
	  haddress.focus();
   }
   else if(trim(ephone.value) == "")
   {
      alert('Please enter an Emergency Phone Number');
	  ephone.focus();
   }
   else if(trim(email.value) == "")
   {
      alert('Please enter your E-Mail address');
	  email.focus();
   }
   //IF PHONE/EMAIL FORMATTING IS CORRECT, SUBMIT!!
   else if(allcheck(pnumber.value,ephone.value))
   {
	  document.register.submit();
   }
}

//CALLS FUNCTIONS TO CHECK PHONE/EMAIL FORMATTING!!
function allcheck(pnum, enumber)
{
	if(!checkPhone(pnum))
		return false;
	if(!checkPhone(enumber))
		return false;
	return true;
}

function trim(str)
{
 return str.replace(/^\s+|\s+$/g,'');
}

function checkPhone( phone ) 
{
  phoneRegex = /^\(\d\d\d\)-\d\d\d-\d\d\d\d$/;
if( !phone.match( phoneRegex ) ) 
	{
  alert( 'Please format your phone number correctly: (555)-555-5555');
  return false;
 }
 return true;
}
</script>
<?php
//FORM START
echo "<form action=\"registeradd.php\" method=\"POST\" name=\"register\">";

echo "<table width=100% border=0>";
	echo "<tr height=60px><td valign=top>";
		echo "<table width=100% height=30px border=0>";
			echo "<tr height=60px><td align=center valign=top>";
				echo "<font size=6 face=\"Verdana\">Register New User</font>";	
			echo "</td></tr>";
		echo "</table>";
	echo "</tr></td>";
	echo "<tr><td align=center valign=top>";
		echo "<table border=0>";
			echo "<tr><td>First Name:</td><td> <input type=\"text\" name=\"FirstName\"></td></tr>";
			echo "<tr><td>Last Name:</td><td> <input type=\"text\" name=\"LastName\"></td></tr>";
			echo "<tr><td>User Name:</td><td> <input type=\"text\" name=\"userName\"></td></tr>";
			echo "<tr><td>Password:</td><td> <input type=\"password\" name=\"Password1\"</td></tr>";
			echo "<tr><td>Re-Type Password:</td><td> <input type=\"password\" name=\"Password2\"</td></tr>";
			echo "<tr><td>Phone Number:</td><td> <input type=\"text\" name=\"PhoneNumber\"></td></tr>";
			echo "<tr><td>E-Mail:</td><td> <input type=\"text\" name=\"EMail\"></td></tr>";
			echo "<tr><td>Address:</td><td> <input type=\"text\" name=\"HomeAddress\"></td></tr>";
			echo "<tr><td>Emergency Phone:</td><td> <input type=\"text\" name=\"EmergencyPhone\"></td></tr>";
			echo "<tr><td>Cat Foster:</td><td><select name=\"CatFoster\"><option value=\"default\" selected=\"selected\">Select</option><option value=\"y\">Yes</option><option value=\"n\">No</option></select></td></tr>";
			echo "<tr><td>Dog Foster:</td><td><select nane=\"DogFoster\"><option value=\"default\" selected=\"selected\">Select</option><option value=\"y\">Yes</option><option value=\"n\">No</option></select></td></tr>";
			echo "<p align=center><tr><td><input type=\"button\" value=\"Register\" onClick=\"checkForm()\">";
			echo "</p>";
		echo "</table>";
	echo "</tr></td>";
echo "</table>";
?>